package yswl.com.klibrary.util;

import android.support.v4.util.ArrayMap;
import android.text.TextUtils;

import java.util.List;
import java.util.Map;

/**
 * 
 * @author nixn@yunhetong.net
 *
 */
public class MParamUtil {
	public static Map<String, Object> getParams(String[] keys, Object[] values) {
		if (keys == null || values == null || keys.length != values.length
				|| keys.length == 0) {
			return null;
		}
		Map<String, Object> params = new ArrayMap<>();
		int size = keys.length;
		for (int i = 0; i < size; i++) {
			params.put(keys[i], values[i]);
		}
		return params;
	}

	public static void put(Map<String, Object> params, String key, String value) {
		if (!TextUtils.isEmpty(value)) {
			params.put(key, value);
		}
	}

	public static void put(Map<String, Object> params, String key,
			String value, String defalue) {
		if (!TextUtils.isEmpty(value)) {
			params.put(key, value);
		} else {
			params.put(key, defalue);
		}
	}

	public static void setList(Map<String, Object> params, List<?> objs,
			String key) {
		if (objs == null || params == null || TextUtils.isEmpty(key))
			return;
		int length = objs.size();
		for (int i = 0; i < length; i++) {
			params.put(key + "[" + i + "]", objs.get(i));
		}
	}

	public static void setList(Map<String, Object> params, String objs[],
			String key) {
		if (objs == null || params == null || TextUtils.isEmpty(key))
			return;
		int length = objs.length;
		for (int i = 0; i < length; i++) {
			params.put(key + "[" + i + "]", objs[i]);
		}
	}
	public static void setList(Map<String, Object> params, int objs[],
			String key) {
		if (objs == null || params == null || TextUtils.isEmpty(key))
			return;
		int length = objs.length;
		for (int i = 0; i < length; i++) {
			params.put(key + "[" + i + "]",objs[i]);
		}
	}
}
